import torch
import torch.nn as nn

# 假设输入特征图大小为 (batch_size, channels, height, width)
input_tensor = torch.randn(1, 64, 8, 8)  # 例如一个 8x8 的特征图

# 使用 Global Average Pooling
gap_layer = nn.AdaptiveAvgPool2d(1)  # GAP 可以通过设置 AdaptiveAvgPool2d(1) 来实现
gap_output = gap_layer(input_tensor)
print("Global Average Pooling output shape:", gap_output.shape)

# 使用 Adaptive Average Pooling
adaptive_layer = nn.AdaptiveAvgPool2d(1)
adaptive_output = adaptive_layer(input_tensor)
print("Adaptive Average Pooling output shape:", adaptive_output.shape)